<html>
<head><meta charset="utf-8"><title>Kill proc-macro child process · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Kill.20proc-macro.20child.20process.html">Kill proc-macro child process</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="194594489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Kill%20proc-macro%20child%20process/near/194594489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Kill.20proc-macro.20child.20process.html#194594489">(Apr 19 2020 at 12:11)</a>:</h4>
<p>I just found that in some weird situations, if <code>rust-analzyer</code> panic / crash accidentally,   the child process spawned for proc-macro did not be killed in Windows. I know it is the default behavior for Windows program. I can't reproduce this in linux,  but I doubt it might happens there too.</p>



<a name="194594554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Kill%20proc-macro%20child%20process/near/194594554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Kill.20proc-macro.20child.20process.html#194594554">(Apr 19 2020 at 12:12)</a>:</h4>
<p>I know <a href="https://stackoverflow.com/questions/53208/how-do-i-automatically-destroy-child-processes-in-windows" title="https://stackoverflow.com/questions/53208/how-do-i-automatically-destroy-child-processes-in-windows">https://stackoverflow.com/questions/53208/how-do-i-automatically-destroy-child-processes-in-windows</a> is a proper solution for this problem in Windows. but  it will make the code complicated as it is platform specific, and I don't know it is worth or not.</p>



<a name="194607911"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Kill%20proc-macro%20child%20process/near/194607911" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Kill.20proc-macro.20child.20process.html#194607911">(Apr 19 2020 at 17:02)</a>:</h4>
<p>This feels like the kind of thing that should be handled by a crate in the ecosystem</p>



<a name="194607918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Kill%20proc-macro%20child%20process/near/194607918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Kill.20proc-macro.20child.20process.html#194607918">(Apr 19 2020 at 17:03)</a>:</h4>
<p>"spawn a child process with automatic cleanup"</p>



<a name="194608112"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Kill%20proc-macro%20child%20process/near/194608112" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Kill.20proc-macro.20child.20process.html#194608112">(Apr 19 2020 at 17:07)</a>:</h4>
<p>If you assume unwinding, storing the handle somewhere and terminating the child on <code>Drop</code> is enough on any platform</p>



<a name="194608350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Kill%20proc-macro%20child%20process/near/194608350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Kill.20proc-macro.20child.20process.html#194608350">(Apr 19 2020 at 17:12)</a>:</h4>
<p>Even I kill the parent process externally ?</p>



<a name="194608534"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Kill%20proc-macro%20child%20process/near/194608534" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Kill.20proc-macro.20child.20process.html#194608534">(Apr 19 2020 at 17:17)</a>:</h4>
<p><a href="https://github.com/oconnor663/duct.py/blob/master/gotchas.md#killing-grandchild-processes" title="https://github.com/oconnor663/duct.py/blob/master/gotchas.md#killing-grandchild-processes">here's duct talking about the adjacent issue of grandchild processes</a></p>



<a name="194608620"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Kill%20proc-macro%20child%20process/near/194608620" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Kill.20proc-macro.20child.20process.html#194608620">(Apr 19 2020 at 17:18)</a>:</h4>
<p>TL;DR of duct's info page is that job objects seem to solve the problem proposed (correct transitive child process cleanup) but *nix doesn't have a good solution yet</p>



<a name="194608631"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Kill%20proc-macro%20child%20process/near/194608631" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Kill.20proc-macro.20child.20process.html#194608631">(Apr 19 2020 at 17:19)</a>:</h4>
<p>And killing the process externally would not be able to assume unwinding</p>



<a name="194640130"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Kill%20proc-macro%20child%20process/near/194640130" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Kill.20proc-macro.20child.20process.html#194640130">(Apr 20 2020 at 07:22)</a>:</h4>
<p>I think if we panic, we should kill the child process (in Drop). If we crash abnormaly (like via sigkill) I don't feel like it is worth it to clean up the child. Although this is possible, cargo implements this here: <a href="https://github.com/rust-lang/cargo/blob/5b620dc044e8999e6bc0193f9e037c4618519547/src/cargo/util/job.rs" title="https://github.com/rust-lang/cargo/blob/5b620dc044e8999e6bc0193f9e037c4618519547/src/cargo/util/job.rs">https://github.com/rust-lang/cargo/blob/5b620dc044e8999e6bc0193f9e037c4618519547/src/cargo/util/job.rs</a></p>



<a name="194640187"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Kill%20proc-macro%20child%20process/near/194640187" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Kill.20proc-macro.20child.20process.html#194640187">(Apr 20 2020 at 07:23)</a>:</h4>
<p>But, I think that we should add an <code>JChild</code> struct to <code>stdx::process</code>, which kills the child on drop.</p>



<a name="194666001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Kill%20proc-macro%20child%20process/near/194666001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Kill.20proc-macro.20child.20process.html#194666001">(Apr 20 2020 at 12:14)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> iirc, the job thing on windows is just for ctrl+c as well</p>



<a name="194666251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Kill%20proc-macro%20child%20process/near/194666251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Kill.20proc-macro.20child.20process.html#194666251">(Apr 20 2020 at 12:17)</a>:</h4>
<p>From the doc comment:</p>
<blockquote>
<p>Job objects have a mode of operation where when all handles to the object are closed it causes all child processes associated with the object to be terminated immediately.</p>
</blockquote>
<p>I think this means that any way of exiting the process will kill all child processes.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>